package oceanlife.pathfinding;

import oceanlife.OLSet;

public class RadialFace implements Comparable<RadialFace>{
	
	//private double border = 10000.0;
	private double faraway =OLSet.border*5.0;
	private Double radian;
	private Pnt origen;
	private Pnt pnt;
	private Pnt lineEnd1;
	private Pnt lineEnd2;
	

	public RadialFace(Pnt origen, Pnt pnt){
		this.pnt = pnt;
		this.origen = origen;
		radian = new Line2(origen,pnt).angle();
		double p1x = faraway*Math.sin(radian-(Math.PI/2.0))+pnt.coord(0);
		double p1y = faraway*Math.cos(radian-(Math.PI/2.0))+pnt.coord(1);
		double p2x = faraway*Math.sin(radian+(Math.PI/2.0))+pnt.coord(0);
		double p2y = faraway*Math.cos(radian+(Math.PI/2.0))+pnt.coord(1);
		lineEnd1 = new Pnt(p1x,p1y);
		lineEnd2 = new Pnt(p2x,p2y);
	}
	
	public RadialFace(Pnt origen, Pnt pnt, Pnt lineEnd1, Pnt lineEnd2){
		this.pnt = pnt;
		this.origen = origen;
		this.lineEnd1 = lineEnd1;
		this.lineEnd2 = lineEnd2;
		radian = new Line2(origen,pnt).angle();
	}	

	public Pnt getLineEnd1() {
		return lineEnd1;
	}

	public void setLineEnd1(Pnt lineEnd1) {
		this.lineEnd1 = lineEnd1;
	}

	public Pnt getLineEnd2() {
		return lineEnd2;
	}

	public void setLineEnd2(Pnt lineEnd2) {
		this.lineEnd2 = lineEnd2;
	}

	public Pnt interscetionPoint(RadialFace rf){
		return rf.getBorderLine().intersectionPoint(this.getBorderLine());
	}
	
	public Pnt getOrigen(){
		return origen;
	}
	
	public double getRadian() {
		return radian;
	}

	public Line2 getBorderLine(){
		return new Line2(lineEnd1,lineEnd2);
	}
	
	public Pnt getPnt() {
		return pnt;
	}

	@Override
	public int compareTo(RadialFace rp) {
		//return this.radian.compareTo(rp.radian);
		double temp = this.pnt.distanceTo(origen) - rp.pnt.distanceTo(origen);
		if(temp < 0){
			return -1;
		} else if(temp == 0){
			return 0;
		} else {
			return 1;
		}
	}
	
	@Override
	public String toString(){
		if(lineEnd1 == null){
			return "o:"+origen+" p:"+pnt+" r:"+radian;			
		} else {
			return "o:"+origen+" p:"+pnt+" r:"+radian+" 1:"+lineEnd1+" 2:"+lineEnd2;			
		}
	}

	@Override
	public boolean equals(Object other){
		if (other instanceof RadialFace && this.pnt.equals(((RadialFace) other).pnt) && this.origen.equals(((RadialFace) other).origen)){
			return true;
		}
		return false;
	}

}
